# encoding: UTF-8
# user：admin at 2018/11/7

from PyQt5.QtWidgets import QTableWidgetItem,QAbstractItemView
from PyQt5.Qt import *

class showTableWidgets():

    def __init__(self):
        pass

    def show_tablewidget(self,list_data,tableWidget):
        list_label = [u'证券代码', u'证券名称', u'净值日期', u'单位净值', u'累计净值', u'日增长率']
        list_col=['zqdm','zqmc','fdate','dwjz','ljjz','rzzl']
        tableWidget.setRowCount(len(list_data))
        tableWidget.setColumnCount(len(list_col))
        tableWidget.setHorizontalHeaderLabels(list_label)

        tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
        tableWidget.resizeRowsToContents()
        tableWidget.resizeColumnsToContents()

        tableWidget.setCornerButtonEnabled(True)

        for index in range(len(list_data)):
            #print(list_data[index])
            for col in range(len(list_col)):
                name_col=list_col[col]

                if name_col=='zqdm':
                    item=QTableWidgetItem(list_data[index][col])
                    item.setTextAlignment(Qt.AlignRight)
                    #item.setFlags(Qt.ItemIsUserCheckable|Qt.ItemIsEnabled)
                    item.setFlags(Qt.ItemIsUserCheckable |
                                  Qt.ItemIsEnabled)

                    tableWidget.setItem(index,col,item)
                elif name_col=='zqmc':
                    item = QTableWidgetItem(list_data[index][1])
                    tableWidget.setItem(index, col, item)
                elif name_col=='fdate':
                    item = QTableWidgetItem(list_data[index][3])
                    tableWidget.setItem(index, col, item)
                elif name_col=='dwjz':
                    item = QTableWidgetItem(str(list_data[index][4]))
                    # print(list_data[index][4])
                    tableWidget.setItem(index, col, item)
                elif name_col=='ljjz':
                    item = QTableWidgetItem(str(list_data[index][5]))
                    #print(list_data[index][5])
                    tableWidget.setItem(index, col, item)
                elif name_col=='rzzl':
                    item = QTableWidgetItem(str(list_data[index][6]))
                    # print(list_data[index][6])
                    tableWidget.setItem(index, col, item)

